package com.py.korona.db.model;

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import com.py.korona.db.UriBuilder;
import com.py.korona.db.model.base.Entity;
import com.py.korona.db.model.base.EntityDescription;
import com.py.korona.db.model.base.EntityProperty;

public class GeoplanEntity extends Entity {
    public static String             FieldNameID        = "_id";
    public static String             FieldNameText      = "text";
    public static String             FieldNameImageData = "imageData";
    public static String             TableName          = "geoplan";
    private static EntityDescription entityDescription_;

    public static EntityDescription entityDescription() {
        if (null == entityDescription_) {
            entityDescription_ = new EntityDescription();
            entityDescription_.addProperty(new EntityProperty(GeoplanEntity.FieldNameID, "integer", null, "primary key autoincrement"));
            entityDescription_.addProperty(new EntityProperty(GeoplanEntity.FieldNameText, "text", null, "not null"));
            entityDescription_.addProperty(new EntityProperty(GeoplanEntity.FieldNameImageData, "BLOB", null, ""));
        }
        return entityDescription_;
    }

    public static String entityTableName() {
        return GeoplanEntity.TableName;
    }

    public static String TableFieldAliasID() {
        return String.format("%s.%s", GeoplanEntity.TableName, GeoplanEntity.FieldNameID);
    }

    public static String TableFieldAliasText() {
        return String.format("%s.%s", GeoplanEntity.TableName, GeoplanEntity.FieldNameText);
    }

    public static String TableFieldAliasImageData() {
        return String.format("%s.%s", GeoplanEntity.TableName, GeoplanEntity.FieldNameImageData);
    }

    public static String uriAuthority() {
        return "GeoplanContentProvider";
    }

    public static String uriBasePath() {
        return "geoplan";
    }
    private byte[] imageData;
    private String text;

    public byte[] getImageData() {
        return imageData;
    }

    public String getText() {
        return text;
    }

    public void setImageData(byte[] imageData) {
        this.imageData = imageData;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    protected ContentValues contentValues() {
        ContentValues contentValues = new ContentValues();
        contentValues.put(GeoplanEntity.FieldNameText, this.getText());
        contentValues.put(GeoplanEntity.FieldNameImageData, this.getImageData());
        return contentValues;
    }

    @Override
    protected Uri objectsListUri() {
        return UriBuilder.objectListUri(GeoplanEntity.uriAuthority(), GeoplanEntity.uriBasePath());
    }

    @Override
    protected void onDataChanged(Cursor cursor) {
        this._id = cursor.getLong(cursor.getColumnIndexOrThrow(GeoplanEntity.FieldNameID));
        this.text = cursor.getString(cursor.getColumnIndexOrThrow(GeoplanEntity.FieldNameText));
        this.imageData = cursor.getBlob(cursor.getColumnIndexOrThrow(GeoplanEntity.FieldNameImageData));
    }
}
